package com.catering.controller;

import com.catering.config.Result;
import com.catering.pojo.DOrderinformation;
import com.catering.service.DOrderinformationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/order")
public class DOrderController {
    @Autowired
    private DOrderinformationService dOrderinformationService;
//    查看自己所有的订单
    @RequestMapping("/list1")
    public List<DOrderinformation> list(Integer uid) {
        System.out.println("接收到订单列表请求，用户ID：" + uid);
        List<DOrderinformation> orders = dOrderinformationService.selectByOrder(uid);
        System.out.println("查询到的订单数量：" + orders.size());
        return orders;
    }
//    生成订单
    @RequestMapping("/insertByOrder")
    @ResponseBody
    public Result insertOrder(@RequestBody DOrderinformation orderinformation) {
        System.out.println("接收到订单插入请求，订单信息：" + orderinformation);
        dOrderinformationService.insertDOrder(orderinformation);
    return Result.success("订单创建成功");
}
//    修改订单的状态，实现取消订单按钮
    @RequestMapping("updateStatus")
    public void updateStatus(Integer oid) {
        System.out.println("接收到订单状态更新请求，订单ID：" + oid );
        dOrderinformationService.updateStatus(oid);
    }

}
